﻿using System.Text;

namespace CodeContrib
{
	public class VCard
	{
		public string City { get; set; }
		public string CompanyName { get; set; }
		public string Country { get; set; }
		public string EmailAddress { get; set; }
		public string FirstName { get; set; }
		public byte[] Image { get; set; }
		public string JobTitle { get; set; }
		public string LastName { get; set; }
		public string MobileNumber { get; set; }
		public string Phone { get; set; }
		public string PostCode { get; set; }
		public string StreetAddress { get; set; }
		public string WebSite { get; set; }

		public override string ToString()
		{
			var vCard = new StringBuilder();
			vCard.AppendLine("BEGIN:VCARD");
			vCard.AppendLine("VERSION:2.1");

			// Name
			vCard.AppendLine("N:" + LastName + ";" + FirstName);

			// Full name
			vCard.AppendLine("FN:" + FirstName + " " + LastName);

			// Address
			vCard.Append("ADR;HOME;PREF:;");
			vCard.Append(StreetAddress + ";");
			vCard.Append(City + ";");
			vCard.Append(PostCode + ";");
			vCard.AppendLine(Country);

			// Other data
			vCard.AppendLine("ORG:" + CompanyName);
			vCard.AppendLine("TITLE:" + JobTitle);
			vCard.AppendLine("TEL;HOME;VOICE:" + Phone);
			vCard.AppendLine("TEL;CELL;VOICE:" + MobileNumber);
			vCard.AppendLine("URL;" + WebSite);
			vCard.AppendLine("EMAIL;PREF;INTERNET:" + EmailAddress);

			vCard.AppendLine("END:VCARD");

			return vCard.ToString();
		}
	}
}